package com.hsjk.szwj.module.train.controller.admin;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCheckoutConfigInfoRespVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminCreateOrUpdateCheckoutConfigReqVO;
import com.hsjk.szwj.module.train.service.ICheckoutConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/09/12 23:47
 **/
@Tag(name = "后台管理 - 分润配置")
@RestController
@RequestMapping("/train/checkout-config")
@Validated
@Slf4j
public class AdminCheckoutConfigController {
    @Resource
    private ICheckoutConfigService checkoutConfigService;


    @GetMapping("/get-by-sku-id")
    @Operation(summary = "根据sku Id 获取分润配置信息")
    @PreAuthorize("@ss.hasPermission('train:checkout-config:query')")
    public CommonResult<AdminCheckoutConfigInfoRespVO> getCheckoutConfigInfoBySkuId(@RequestParam("skuId") Long skuId) {
        return success(checkoutConfigService.getCheckoutConfigInfoBySkuId(skuId));
    }

    @PostMapping("/create-or-update")
    @Operation(summary = "创建或更新分润配置")
    @PreAuthorize("@ss.hasPermission('train:checkout-config:update')")
    public CommonResult<Boolean> createOrUpdateCheckoutConfig(@RequestBody @Valid
                                                              AdminCreateOrUpdateCheckoutConfigReqVO reqVO) {
        return success(checkoutConfigService.createOrUpdateCheckoutConfig(reqVO));
    }
}
